perm filename SYNTAX.PUB[206,JMC]1 blob sn#005312 filedate 1971-11-24 generic text, type T, neo UTF8
00100	.NOFILL CENTER
00200	SYNTAX DIRECTED COMPUTATION
00300	.FILL RETAIN TURN ON "_↓","↓_"
00400	
00500	
00600		It is often more convenient to describe certain kinds of
00700	computation with symbolic expressions by "syntax transformations"
00800	than by recursive LISP functions.  For example, consider the
00900	simplification of expressions in a binary  PLUS  and  TIMES  where
01000	the number  0  is to be eliminated from sums, the number  1  is to
01100	be eliminated from products, products containing  0  are to be
01200	replaced by  0, and sums and products of one element are to be
01300	replaced by that element.
01400	This may be accomplished by the function  simplifya  defined by
01500	
01550	.begin nofill
01600		simplifya e ← ↓_if at_↓ e ↓_then_↓ e
01700				↓_else_↓ {simplifya ↓_ad_↓ e,simplifya ↓_add_↓ e}
01800				[λwz. ↓_if a_↓ e ↓_eq_↓ PLUS ↓_then_↓
01900					[↓_if_↓ w = 0 ↓_then_↓ z
02000					↓_else if_↓ z = 0 ↓_then_↓ w
02100					↓_else <PLUS w z>]
02200					↓_else if_↓ w = 0 ∨ z = 0 ↓_then_↓ 0
02300					↓_else if_↓ w = 1 ↓_then_↓ z
02400					↓_else if_↓ z = 1 ↓_then_↓ w
02500					↓_else_↓ <TIMES w z>.
02600	.end